Restore configurability of vif bring up script and passing arguments to the script.
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Fri, 2 Sep 2005 14:15:49 +0000 (14:15 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Fri, 2 Sep 2005 14:15:49 +0000 (14:15 +0000)
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
linux-2.6-xen-sparse/include/asm-xen/xenbus.h
tools/examples/xen-backend.agent
tools/python/xen/xend/XendDomainInfo.py

index 27314dd62207c1ac32efd31fcbf7768f62f066ec..80050f9c18d2e462fc3578aacd6403a78c314f6a 100644 (file)
@@ -160,11 +160,49 @@ static void backend_changed(struct xenbus_watch *watch, const char *node)
                }
 #endif
 
+               kobject_hotplug(&dev->dev.kobj, KOBJ_ONLINE);
+
                /* Pass in NULL node to skip exist test. */
                frontend_changed(&be->watch, NULL);
        }
 }
 
+static int netback_hotplug(struct xenbus_device *xdev, char **envp,
+                          int num_envp, char *buffer, int buffer_size)
+{
+       struct backend_info *be;
+       netif_t *netif;
+       char **key, *val;
+       int i = 0, length = 0;
+       static char *env_vars[] = { "script", "domain", "mac", "bridge", "ip",
+                                   NULL };
+
+       be = xdev->data;
+       netif = be->netif;
+
+       add_hotplug_env_var(envp, num_envp, &i,
+                           buffer, buffer_size, &length,
+                           "vif=%s", netif->dev->name);
+
+       key = env_vars;
+       while (*key != NULL) {
+               val = xenbus_read(xdev->nodename, *key, NULL);
+               if (!IS_ERR(val)) {
+                       char buf[strlen(*key) + 4];
+                       sprintf(buf, "%s=%%s", *key);
+                       add_hotplug_env_var(envp, num_envp, &i,
+                                           buffer, buffer_size, &length,
+                                           buf, val);
+                       kfree(val);
+               }
+               key++;
+       }
+
+       envp[i] = NULL;
+
+       return 0;
+}
+
 static int netback_probe(struct xenbus_device *dev,
                         const struct xenbus_device_id *id)
 {
@@ -249,6 +287,7 @@ static struct xenbus_driver netback = {
        .ids = netback_ids,
        .probe = netback_probe,
        .remove = netback_remove,
+       .hotplug = netback_hotplug,
 };
 
 void netif_xenbus_init(void)
index b73201a0f4c6fc3ad0a6444381e1c2a458e7ab10..2c9bd9877e594d3f47484fa64a14055ab6e8fa9a 100644 (file)
@@ -147,6 +147,39 @@ static int backend_bus_id(char bus_id[BUS_ID_SIZE], const char *nodename)
        return 0;
 }
 
+static int xenbus_hotplug_backend(struct device *dev, char **envp,
+                                 int num_envp, char *buffer, int buffer_size)
+{
+       struct xenbus_device *xdev;
+       int i = 0;
+       int length = 0;
+
+       if (dev == NULL)
+               return -ENODEV;
+
+       xdev = to_xenbus_device(dev);
+       if (xdev == NULL)
+               return -ENODEV;
+
+       /* stuff we want to pass to /sbin/hotplug */
+       add_hotplug_env_var(envp, num_envp, &i,
+                           buffer, buffer_size, &length,
+                           "XENBUS_TYPE=%s", xdev->devicetype);
+
+       /* terminate, set to next free slot, shrink available space */
+       envp[i] = NULL;
+       envp = &envp[i];
+       num_envp -= i;
+       buffer = &buffer[length];
+       buffer_size -= length;
+
+       if (dev->driver && to_xenbus_driver(dev->driver)->hotplug)
+               return to_xenbus_driver(dev->driver)->hotplug
+                       (xdev, envp, num_envp, buffer, buffer_size);
+
+       return 0;
+}
+
 static int xenbus_probe_backend(const char *type, const char *uuid);
 static struct xen_bus_type xenbus_backend = {
        .root = "backend",
@@ -156,6 +189,7 @@ static struct xen_bus_type xenbus_backend = {
        .bus = {
                .name  = "xen-backend",
                .match = xenbus_match,
+               .hotplug = xenbus_hotplug_backend,
        },
        .dev = {
                .bus_id = "xen-backend",
index acdf931acc74cbb75c5393ac4e4430f356f55262..b792efe8c84365c152044ef5aa37aaef10e3bcaa 100644 (file)
@@ -64,6 +64,7 @@ struct xenbus_driver {
        int (*remove)(struct xenbus_device *dev);
        int (*suspend)(struct xenbus_device *dev);
        int (*resume)(struct xenbus_device *dev);
+       int (*hotplug)(struct xenbus_device *, char **, int, char *, int);
        struct device_driver driver;
 };
 
index a708aad8f3431a04a51fb55f93768c5d7c0bc17d..0058bd2842a58cf271ac0729c5067328a4e4ac14 100755 (executable)
@@ -1,21 +1,25 @@
 #! /bin/sh
 
-#DEVPATH=/devices/xen-backend/vif-1-0
 #ACTION=add
+#DEVPATH=/devices/xen-backend/vif-1-0
+#PHYSDEVDRIVER=vif
+#XENBUS_TYPE=vif
 
 PATH=/etc/xen/scripts:$PATH
 
-DEV=$(basename "$DEVPATH")
 case "$ACTION" in
   add)
-    case "$DEV" in
-      vif-*)
-        vif=$(echo "$DEV" | sed 's/-\([0-9]*\)-\([0-9]*\)/\1.\2/')
-        vif-bridge up domain=unknown vif="$vif" mac=fe:ff:ff:ff:ff:ff bridge=xen-br0 >/dev/null 2>&1
+    ;;
+  remove)
+    ;;
+  online)
+    case "$PHYSDEVDRIVER" in
+      vif)
+        [ -n "$script" ] && $script up
         ;;
     esac
     ;;
-  remove)
+  offline)
     ;;
 esac
 
index ee8edd566f95dff9cb086ebebce9149e6fcc82fa..dcd6bcc52948646764c5893579640043cbcb6001 100644 (file)
@@ -430,6 +430,15 @@ class XendDomainInfo:
             return
 
         if type == 'vif':
+            from xen.xend import XendRoot
+            xroot = XendRoot.instance()
+
+            def _get_config_ipaddr(config):
+                val = []
+                for ipaddr in sxp.children(config, elt='ip'):
+                    val.append(sxp.child0(ipaddr))
+                return val
+
             backdom = domain_exists(sxp.child_value(devconfig, 'backend', '0'))
 
             log.error(devconfig)
@@ -437,6 +446,14 @@ class XendDomainInfo:
             devnum = self.netif_idx
             self.netif_idx += 1
 
+            script = sxp.child_value(devconfig, 'script',
+                                     xroot.get_vif_script())
+            script = os.path.join(xroot.network_script_dir, script)
+            bridge = sxp.child_value(devconfig, 'bridge',
+                                     xroot.get_vif_bridge())
+            mac = sxp.child_value(devconfig, 'mac')
+            ipaddr = _get_config_ipaddr(devconfig)
+
             # create backend db
             backdb = backdom.db.addChild("/backend/%s/%s/%d" %
                                          (type, self.uuid, devnum))
@@ -444,6 +461,12 @@ class XendDomainInfo:
             # create frontend db
             db = self.db.addChild("/device/%s/%d" % (type, devnum))
             
+            backdb['script'] = script
+            backdb['domain'] = self.name
+            backdb['mac'] = mac
+            backdb['bridge'] = bridge
+            if ipaddr:
+                backdb['ip'] = ' '.join(ipaddr)
             backdb['frontend'] = db.getPath()
             backdb['frontend-id'] = "%i" % self.id
             backdb['handle'] = "%i" % devnum
@@ -452,8 +475,7 @@ class XendDomainInfo:
             db['backend'] = backdb.getPath()
             db['backend-id'] = "%i" % backdom.id
             db['handle'] = "%i" % devnum
-            log.error(sxp.child_value(devconfig, 'mac'))
-            db['mac'] = sxp.child_value(devconfig, 'mac')
+            db['mac'] = mac
 
             db.saveDB(save=True)